package cn.hesion.exersice;
/**
 * ClassName: SelectSort <br/>
 * Description: <br/>
 * date: 2022/5/12 5:56<br/>
 *
 * @author Hesion<br />
 * @version
 * @since JDK 1.8
 */

import java.util.Arrays;

/**
 * @author: hesion
 * @create: 2022-05-12 05:56
 **/
public class SelectSort {
    public static void main(String[] args) {
        int[] nums = new int[]{8, 3, 1, 6, 9};
        int n = nums.length;


        for (int i = 0; i < n; i++) {
            int minNum = nums[i];
            int minIndex = i;
            for (int j = i + 1; j < n; j++) {
                if (nums[j] < minNum) {
                    minNum = nums[j];
                    minIndex = j;
                }
            }
            if (minIndex != i) {
                nums[minIndex] = nums[i];
                nums[i] = minNum;
            }
        }

        System.out.println(Arrays.toString(nums));
    }
}
